﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MTRC.ODMS.Web.SOM.Popup
{
    public partial class PopupCriteriaNew : BasePage_SOM
    {
        #region Property
        public string MenuID
        {
            get
            {
                return string.Concat(this.ViewState["_menuID"]);
            }
            set
            {
                this.ViewState["_menuID"] = value;
            }
        }
        #endregion

        #region  Page Load
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.ChangeLanguage += new ChangeLanguageEventHandler(ChangeLanguage_Function);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                SetLanguage();
                //if (Request.QueryString["station"] != null && Request.QueryString["station"].ToString() != string.Empty)
                //{
                //    txtStation.Text = Request.QueryString["station"];
                //}
                if (Request.QueryString["MenuID"] != null && Request.QueryString["MenuID"].ToString() != string.Empty)
                {
                    this.MenuID = Request.QueryString["MenuID"];
                }
            }
        }
        #endregion

        #region Event
        public void ChangeLanguage_Function(object sender, EventArgs e)
        {
            //set control text about multi-language of page
            SetLanguage();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string cruteriaName = txtCriteria.Text.Trim();
            if (cruteriaName == "" || string.IsNullOrEmpty(cruteriaName))
            {
                this.PAlert(this.GetMessage("SOM_PassengerFlow_CriteriaNotNullOrEmpty"));
                return;
            }
            //else if (cruteriaName == "Default Criteria")
            else if (cruteriaName == Request.QueryString["DefaultCriteria"])//Add by jack 20160125 ISU11 fixed for harcode 'Default Criteria'
            {   //default criteria
                this.PAlert(this.GetMessage("SOM_PassengerFlow_DefaultCriteriaCanNotCreate"));
                return;
            }
            int criteria = ExistCriteriaName(cruteriaName, this.MenuID, this.ODMUser.UserGroupID);
            if (criteria>0)
	        {
                this.PAlert(this.GetMessage("SOM_PatronageExcelReport_CannotCreateExists"));
                return;
	        }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "save", "PersonHoldCriteria('" + cruteriaName + "');",true);
                //ToolkitScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", "PersonHoldStation('" + HttpUtility.HtmlDecode(PersonHoldStationKye) + "');", true); 
            }
        }
        #endregion

        #region Method
        /// <summary>
        /// set language
        /// </summary>
        public void SetLanguage()
        {
            this.lblCriteria.Text = this.GetLabel("SOM_PassengerFlow_Criteria", false);
            //this.lblStation.Text = this.GetLabel("COM_Station", false);
            //this.lblDate.Text = this.GetLabel("COM_Date", false);
            this.btnSave.Text = this.GetLabel("COM_Save", false);
            this.btnCancel.Text = this.GetLabel("COM_Cancel",false);
        }

        public static int ExistCriteriaName(string CriteriaName, string MenuID, int userGroupID)
        {

            int criteriaId = 0;
            MTRC.ODMS.DAL.SOM.PassengerFlow.PassengerSelectionCriteria.ExistCriterianName(CriteriaName, MenuID, userGroupID, out criteriaId);

            return criteriaId;
        }
        #endregion
    }
}